package cognitivetouch;

import cognitivetouch.colorSpan.ColorWheel;
import cognitivetouch.colorSpan.Judge;
import cognitivetouch.colorSpan.MouseLib;
import cognitivetouch.colorSpan.ScreenLib;
import cognitivetouch.colorSpan.Session;
import org.lwjgl.opengl.Display;

public class MainCW {

    final private ColorWheel CWLib;
    final private MouseLib mouseLib;
    final private Judge judge;
    final private ScreenLib screen;
    private int totalSession = 1;
    private int trialsPerSession = 1;
    private Session s;
    private int currentSession;

    public MainCW() {
        CWLib = new cognitivetouch.colorSpan.ColorWheel();
        mouseLib = new MouseLib();
        judge = new Judge(CWLib, mouseLib);
        screen = new ScreenLib();
    }

    public void start() {
        screen.initScreen();
        screen.initOpenGL();
        s = new Session(5, judge);
        currentSession = 1;
//        float oldA = -2;
//        boolean toExit = false;
        //init new session
        while ((!Display.isCloseRequested())) {
            screen.glClear();
//            CWLib.renderOpenGL(screen.getCenterX(), screen.getCenterY());
//            switch (judge.judge()) {
//                case updateColor:
//                    oldA = judge.getA();
//                    CWLib.drawColorLine(judge.getA());
//                    break;
//                case ignore:
//                    CWLib.drawColorLine(oldA);
//                    break;
//                case exit:
//                    toExit = true;
//            }
            if (s.executeToFinish()) {
                if (currentSession < totalSession) {
                    s = new Session(trialsPerSession, judge);
                } else {
                    break;
                }
            }

            Display.update();
            Display.sync(60);

        }
        destroy();
    }

    public static void main(String[] argv) {
        MainCW cw = new MainCW();
        cw.start();
    }

    private void destroy() {
        mouseLib.destroy();
        Display.destroy();

    }

}
